<jsp:useBean id="korisnik"
	type="rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Korisnik"
	scope="session" />
<jsp:useBean id="voznje"
	type="java.util.Collection<rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Voznja>"
	scope="session" />

<html>
<head>
<title><fmt:message key="prikazNezapocetihVoznji" /></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link href="/${initParam.nazivAplikacije}/css/tema.css" rel="stylesheet"
	type="text/css" />
<script type="text/javascript"
	src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCboL0NZynp65Ju2VnLu0fx49ea4pVLbqU&sensor=false">
	
</script>
<script type="text/javascript">
	var marker1 = null;
	var mapa = null;
	
	function inicijalizujMapu() {
		var opcije = {
				// koordinate Novog Sada
				center : new google.maps.LatLng(45.2464, 19.8518),
				zoom : 8,
				mapTypeId : google.maps.MapTypeId.ROADMAP
			};
		mapa = new google.maps.Map(document.getElementById("platno"), opcije);
	}

	/* 
	 * brise stari i postavlja novi marker
	 */
	function prikaziIshodiste(sirina, duzina) {
		// ako postoji marker, ukloni ga
		if (marker1 != null) {
			marker1.setMap(null);
			marker1 = null;
		}

		var mojeOpcije = {
				center: new google.maps.LatLng(sirina, duzina),
				zoom : 14,
				mapTypeId : google.maps.MapTypeId.ROADMAP
		};
		
		mapa = new google.maps.Map(document.getElementById("platno"), mojeOpcije);		
		
		// ... i postavi novi
		marker1 = new google.maps.Marker({
			map : mapa,
			position : new google.maps.LatLng(sirina, duzina)
		});
		
		marker1.setTitle('<fmt:message key="ishodisnaAdresa" />');
		
		// dobijena od GeoCoder servisa
		var uredjenaAdresa;
		
		var geokoder = new google.maps.Geocoder();
		geokoder
				.geocode(
						{
							"location" : new google.maps.LatLng(sirina, duzina)
						},
						function(rezultati, status) {
							if (status == google.maps.GeocoderStatus.OK) {
								prozorcicAdresa(marker1, rezultati[0].formatted_address);
							} else {
								alert('<fmt:message key="porukaMapeGreska" />'
										+ ': ' + status);
							}
						});
	}

	/*
	 * Info prozor sa adresom markera
	 */
	function prozorcicAdresa(marker, poruka) {
		var infoProzorcic = new google.maps.InfoWindow({
			content : poruka
		});

		google.maps.event.addListener(marker, 'click', function() {
			infoProzorcic.open(marker.get('map'), marker);
		});
	}
</script>
</head>
<body onload="inicijalizujMapu()">
	<table class="zaglavlje">
		<thead>
			<tr>
				<th><a
					href="/${initParam.nazivAplikacije}/PrikazZavrsenihVoznjiKontroler"><fmt:message
							key="prikazZavrsenihVoznji" /></a></th>
				<th><a
					href="/${initParam.nazivAplikacije}/jsp/promenaLicnihPodataka.jsp"><fmt:message
							key="promenaPodataka" /></a></th>
				<th><a
					href="/${initParam.nazivAplikacije}/jsp/promenaLozinke.jsp"><fmt:message
							key="promenaLozinke" /></a></th>
				<th><a href="/${initParam.nazivAplikacije}/OdjavaKontroler"><span
						style="font-style: italic;"> <fmt:message key="odjava" />
					</span> </a></th>
			</tr>
		</thead>
	</table>
	<table class="glavna">
		<thead>
			<tr>
				<th>&nbsp;</th>
				<th><fmt:message key="ishodisnaAdresa" /></th>
				<th><fmt:message key="brojOsoba" /></th>
				<th><fmt:message key="zapreminaPrtljaga" /></th>
				<th><fmt:message key="masaPrtljaga" /></th>
				<th>&nbsp;</th>
				<th>&nbsp;</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach var="voznja" items="${voznje}" varStatus="status">
				<tr>
					<td>${status.count}</td>
					<td>${voznja.ishodiste.adresa}</td>
					<td>${voznja.brojOsoba}</td>
					<td>${voznja.zapreminaPrtljaga}</td>
					<td>${voznja.masaPrtljaga}</td>
					<td><button
							onclick="prikaziIshodiste(${voznja.ishodiste.y}, ${voznja.ishodiste.x})">
							<fmt:message key="prikazi" />
						</button></td>
					<td>
						<form name="forma"
							action="/${initParam.nazivAplikacije}/jsp/zavrsavanjeVoznje.jsp"
							method="get">
							<input type="submit" name="zapocniVoznju"
								value="<fmt:message key="zapocniVoznju" />" /><input
								type="hidden" name="voznjaId" value="${voznja.id}" /> <input
								type="hidden" name="ishodisnaSirina"
								value="${voznja.ishodiste.y}" /> <input type="hidden"
								name="ishodisnaDuzina" value="${voznja.ishodiste.x}" />
						</form>
					</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<div id="platno"></div>
</body>
</html>
